<template>
  <div>
    <el-card>
      <el-tabs>
        <el-tab-pane label="登录账户设置">
          <el-form ref="userForm" label-width="120px" style="margin-left: 120px; margin-top:30px" :model="userDetail" :rules="rules">
            <el-form-item label="姓名:" prop="username">
              <el-input v-model="userDetail.username" style="width:300px" />
            </el-form-item>
            <el-form-item label="密码:" prop="password">
              <el-input v-model="userDetail.password" style="width:300px" type="password" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submit">更新</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情">
          <user-info />
        </el-tab-pane>
        <el-tab-pane label="岗位信息">
          <job-info />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { getUserDetail } from '@/api/user'
import { saveEmployeeDetail } from '@/api/employee'
import userInfo from './components/userInfo.vue'
import JobInfo from './components/jobInfo.vue'
export default {
  components: { userInfo, JobInfo },
  data() {
    return {
      employeeId: this.$route.params.id,
      userDetail: {},
      rules: {
        username: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 12, message: '密码长度为6-12', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getEmployeeList()
  },
  methods: {
    // 获取员工详情信息
    async getEmployeeList() {
      const res = await getUserDetail(this.employeeId)
      // console.log(res)
      this.userDetail = { ...res, password: '' }
    },
    // 更新姓名密码
    async submit() {
      await this.$refs.userForm.validate()
      await saveEmployeeDetail(this.userDetail)
      this.$message.success('更新成功')
    }
  }
}
</script>

<style>

</style>
